
Partial Class Secure_WebAdmin_RoleManager
    Inherits baseWebPage

    Protected Function IsDeletableRole(ByVal roleName As String) As Boolean
        Select Case roleName
            Case "WebAdmins", "QuestionnaireAdmins", "QuestionnaireManagers"
                Return False
            Case Else
                Return True
        End Select
    End Function

    Protected Sub gvUsersInRole_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvUsersInRole.RowCommand
        If e.CommandName = "UserDetail" Then
            Dim row As GridViewRow = gvUsersInRole.Rows(e.CommandArgument)
            MyBase.SetPreviousPage("page=" & gvRoles.PageIndex & "&index=" & gvRoles.SelectedIndex)
            Session("core_UserName") = CType(row.Cells(0).Controls(0), LinkButton).Text
            Response.Redirect("MembershipDetails.aspx")
        End If
    End Sub

    Protected Sub gvRoles_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvRoles.RowCommand
        Select Case e.CommandName
            Case "Edit"
                gvRoles.SelectedIndex = -1
            Case "Select"
                gvRoles.EditIndex = -1
        End Select
        gvRoles.FooterRow.Visible = False
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack Then
            Exit Sub
        End If
        Dim pageIndex As String = Request.QueryString("page")
        Dim Index As String = Request.QueryString("index")
        If String.IsNullOrEmpty(pageIndex) Or String.IsNullOrEmpty(Index) Then
            Exit Sub
        End If
        Try
            gvRoles.PageIndex = pageIndex
            gvRoles.SelectedIndex = Index
        Catch ex As Exception
            Exit Sub
        End Try
    End Sub

    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        If Not User.IsInRole("WebAdmins") Then
            Response.Redirect("Default.aspx")
        End If
    End Sub

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        lbutNew.Enabled = (gvRoles.EditIndex < 0)
    End Sub

    Protected Sub lbutNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbutNew.Click
        With gvRoles
            .FooterRow.Visible = True
            .PageIndex = .PageCount - 1
            .SelectedIndex = -1
            Dim txtRoleName As TextBox = .FooterRow.FindControl("txtRoleName")
            Dim txtDescription As TextBox = .FooterRow.FindControl("txtDescription")
            txtRoleName.Text = ""
            txtDescription.Text = ""
        End With
    End Sub

    Protected Sub iButOk_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
        With gvRoles
            Dim txtRoleName As TextBox = .FooterRow.FindControl("txtRoleName")
            Dim txtDescription As TextBox = .FooterRow.FindControl("txtDescription")
            odsRoles.InsertParameters("roleName").DefaultValue = txtRoleName.Text
            odsRoles.InsertParameters("desc").DefaultValue = txtDescription.Text
            odsRoles.Insert()
            .DataBind()
        End With
    End Sub

End Class
